fix(claude-cli): surface is_error result events, not raw JSON dump - #751
Open
HUAN2022A wants to merge 1 commit into
Open
fix(claude-cli): surface is_error result events, not raw JSON dump#751HUAN2022A wants to merge 1 commit into
HUAN2022A wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #708
Problem
When the local Claude Code CLI's OAuth session expires, chat fails with a multi-hundred-character raw stdout JSON dump instead of the friendly "Claude Code CLI is not authenticated" message that already exists for the stderr case.
Root cause
All three mechanisms confirmed in code:
parseLineinsrc/lib/claude-cli-transport.tsreturnsnullfor every"type":"result"event without inspectingis_error/result. But in--output-format stream-jsonmode the CLI reports fatal errors exactly that way:{"type":"result","subtype":"success","is_error":true,"result":"Failed to authenticate: OAuth session expired..."}(thesubtypeis misleadingly "success";is_erroris what matters).unparsedLinesand surfaces via the generic "couldn't parse" fallback inbuildExitError()— the dedicated auth branch never runs because it only checks stderr, which is empty here./unauthenticated|please.*log\s*in|authentication.*failed/idoes not match "Failed to authenticate: OAuth session expired..." (reversed word order, "authenticate" vs "authentication").Fix
createClaudeCodeStreamParser()now returns a parser with an optionalonFatalErrorside channel; aresultevent withis_error: truesurfacesobj.resultthrough it instead of being dropped. Successfulresultevents behave exactly as before.streamClaudeCodeCli()captures that text and passes it tobuildExitError()as a new optional 4th argument (also used with priority in the "exited successfully but no content" branch).buildExitError()matches auth patterns againststderr + resultErrortogether, addingfailed to authenticate/oauth session expiredto the regex. Non-authresultErrornow wins over the raw stdout dump: the user sees the CLI's own one-line failure instead of a JSON wall.No Rust changes — the Tauri side only forwards stdout lines verbatim.
Testing
src/lib/__tests__/claude-cli-transport.test.ts: parser (real issue payload signalsonFatalErroronce; missing/blank result does not; successful result unchanged),buildExitError(auth message wins over the JSON dump, reversed phrasing matches, non-auth result rendered as a single clean line), and one end-to-endstreamClaudeCodeClicase emitting the is_error result + done.npx vitest run src/lib/__tests__/claude-cli-transport.test.ts: 31 passed (23 existing, no regressions)npm run test:mocks: 132 files / 1884 tests passednpm run typecheck: clean